package com.longxi.tianjintianbao.ui.adapter.multitype.assetscheck;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.greedao.entity.InventoryChild;
import com.longxi.tianjintianbao.listener.AdapterListener;
import com.longxi.tianjintianbao.model.assetscheck.Test;
import com.longxi.tianjintianbao.model.task.Task;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class TestViewBinder extends ItemViewBinder<InventoryChild, TestViewBinder.ViewHolder> {

    OnClickListener listener;

    public TestViewBinder(OnClickListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_test, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull InventoryChild inventoryChild) {
        holder.tvName.setText("资产名称:" + inventoryChild.name +
                "\n资产编号:" +inventoryChild.number +
                "\n资产分类:" + inventoryChild.cagegory);

        String state = "";
        switch (inventoryChild.isdraft) {
            case "0":
                state = "未盘点";
                break;
            case "1":
                state = "未上传";
                break;
            case "2":
                state = "已上传";
                break;
            case "3":
                state = "未上传";
                break;
        }

        if (inventoryChild.state.equals("0")) {
            holder.tvState.setText(state);
        }else{
            holder.tvState.setText(state + "\n盘盈");
        }


        holder.llBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onClick(holder.getAdapterPosition());
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout llBtn;
        TextView tvName;
        TextView tvState;
        ViewHolder(View itemView) {
            super(itemView);
            llBtn = itemView.findViewById(R.id.llBtn);
            tvName = itemView.findViewById(R.id.tvName);
            tvState = itemView.findViewById(R.id.tvState);
        }
    }

    public interface OnClickListener {
        void onClick(int position);
    }
}
